// 文字列表请求封装

// 导入request
import request from '@/utils/request.js'

export const getArticle = params => {
  return request({
    method: 'GET',
    url: '/v1_1/articles',
    params
  })
}

/**
 *  获取文章详情列表
 * @param {String} id  文章id
 */
export const getArticleDetails = id => {
  return request({
    method: 'GET',
    url: `/v1_0/articles/${id}`
  })
}

/**
 * 关注或取消关注
 * @param {Boolean} cancelOradd
 * @param {String} target
 */
export const sendCancelOraddFollow = (cancelOradd, target) => {
  if (cancelOradd) {
    return request({
      method: 'DELETE',
      url: '/v1_0/user/followings/' + target
    })
  } else {
    return request({
      method: 'POST',
      url: '/v1_0/user/followings',
      data: {
        target
      }
    })
  }
}

export const delOrAddCollect = (delOrAdd, target) => {
  if (delOrAdd) {
    return request({
      method: 'DELETE',
      url: '/v1_0/article/collections/' + target
    })
  } else {
    return request({
      method: 'POST',
      url: '/v1_0/article/collections',
      data: {
        target
      }
    })
  }
}
